<?php
/*
 * Created on 05.01.2006
 *
 */

/**
 * Creates a hidden field with the doc id for applications working in editor view
 * attributes:
 * datasetvar
 * type
 *
 * opt.
 * width
 * height
 * maxwidth
 * maxheight
 */
class cms_prepareelementHandler
{

    var $value;
    var $optiontext;
    var $selected;

    function startElement (& $sender, $attrs)
    {
        if (!isset($attrs['datasetvar']))
        {
            die ("cms:prepareelement must have attribute datasetvar (variablename of the dataset)");
        }
        if (!isset($attrs['type']))
        {
            die ("cms:prepareelement must have attribute type");
        }
        $conf = array('attrs' => array());
        if (isset($attrs['width']) || isset($attrs['height']) || isset($attrs['ismax'])) {
            $conf = array('attrs' => array('WIDTH' => $attrs['width'], 'HEIGHT' => $attrs['height'], 'MAXWIDTH' => $attrs['maxwidth'], 'MAXHEIGHT' => $attrs['maxheight']));
        }
        $sender->appendCode('$__element = $actionform->get('.$attrs['datasetvar'].');$__element[\'type\'] = '.$attrs['type'].';$GLOBALS[\'tpl\']->prepareElement($__element, \'\', '.var_export($conf, true).');$actionform->set('.$attrs['datasetvar'].', $__element);'."\n");
    }
    
    function endElement (& $sender)
    {
    }

} 

?>